<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Friend_link extends REST_Controller {

    function __construct(){  
        
        parent::__construct();  
        $this->returnInfo = lang('returnInfo');
        $this->rdata['returnNo'] = '0000';
        $this->rdata['returnInfo'] = $this->returnInfo['0000'];
        $this->rdata['returnTime'] = time();
        $this->rdata['returnData'] = (object)array();
    }

    public function index_get() {

        echo 'welcome.';

        // $this->load->model('test_model', 'mtest');
        // // $row = $this->mtest->update_one_cache(FALSE,array('modify_at' => date('Y-m-d H:i:s')),array('id >' => 0));
        // $row = $this->mtest->get_list_where_cache(array('id >' => 0));
        // var_dump($row);
    }

    public function list_get(){


        //新闻类型 默认1
        //字典 行业新闻 1 发标公告 2 网站公告 3 活动公告 4
        $type = intval($this->get('type'));
        if (!$type || !is_numeric($type)) {

            $type = 1;
        } 

        $where['status'] = 1;
        $where['type'] = $type;
        $this->load->model('friend_link_model','mfri');

        $limit  = 100;
        $start  = 0;
        $order  = array("id"=>'desc');
        $fields = 'id,status,title,link,photo';
        $table  = FALSE;
        $expire = 604800; //stroing for a minute;
        $result = $this->mfri->get_list_where_cache($limit,$start,$order,$where,$fields,FALSE,$expire);
        //数据库错误
        if (!$result) {
            $this->response($this->rdata);
        }

        $list = array();
        foreach ($result as $key => $value) {
            $tmp = array();
            $tmp['status'] = $value['status'];
            $tmp['link'] = $value['link'];
            $tmp['title'] = $value['title'];
            $photo = one_upload($value['photo']);
            $tmp['photo'] = isset($photo['url'])?UPLOAD_URL.$photo['url']:"";
            $list[] = $tmp;
        }
        $this->rdata['returnData']->list = $list;
        $this->response($this->rdata);
    }


}